package com.duqc.redis;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

/**
 * @ClassName RedisKeyExpirationListener
 * @Description redis 监听key值过期-定义监听器，实现KeyExpirationEventMessageListener接口
 * @Author duqc
 * @Date 2022/2/15
 **/
@Component
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {

    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String valueOf = String.valueOf(message);
        System.out.println("过期的key：" + valueOf);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("dadaaddaddadadadadadada");
    }
}
